﻿using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;

namespace CoreEx.ServiceModel
{
    /// <summary>
    /// Provides a base class for implementing the <see cref="IOperationBehavior"/> interface.
    /// </summary>
    public abstract class OperationBehaviorBase : IOperationBehavior, IInitialize
    {
        /// <summary>
        /// Gets the <see cref="IServiceContainer"/> that 
        /// created this <see cref="IOperationBehavior"/> instance.
        /// </summary>
        protected IServiceContainer ServiceContainer { get; private set; }

        /// <summary>
        /// Implement to confirm that the operation meets some intended criteria.
        /// </summary>
        /// <param name="operationDescription">The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.</param>
        public virtual void Validate(OperationDescription operationDescription) { }


        /// <summary>
        /// Implements a modification or extension of the service across an operation.
        /// </summary>
        /// <param name="operationDescription">The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.</param>
        /// <param name="dispatchOperation">The run-time object that exposes customization properties for the operation described by <paramref name="operationDescription"/>.</param>
        public virtual void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {

        }

        /// <summary>
        /// Implements a modification or extension of the client across an operation.
        /// </summary>
        /// <param name="operationDescription">The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.</param>
        /// <param name="clientOperation">The run-time object that exposes customization properties for the operation described by <paramref name="operationDescription"/>.</param>
        public virtual void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {

        }

        /// <summary>
        /// Implement to pass data at runtime to bindings to support custom behavior.
        /// </summary>
        /// <param name="operationDescription">The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.</param>
        /// <param name="bindingParameters">The collection of objects that binding elements require to support the behavior.</param>
        public virtual void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
        {

        }

        /// <summary>
        /// Initializes this service instance.
        /// </summary>        
        public virtual void Initialize(IServiceContainer source)
        {
            ServiceContainer = source;
        }
    }
}